package com.tobby.camelinaction.synchronicity;

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;

public class SyncMultipleThreads extends CamelTestSupport {

	@Override
	protected RouteBuilder createRouteBuilder() {
		return new RouteBuilder() {

			@Override
			public void configure() throws Exception {
				// route the message to a log so we can see details about MEP and thread name
				from("seda:start").to("log:A")
						// cause this route be use multiple threads
						.threads(5, 10)
						// and then set a reply to the caller
						.transform(constant("Bye Camel")).to("log:B");
			}
		};
	}

	@Test
	public void testAsyncInOut() throws InterruptedException {
		String body = "Hello Camel";

		// send an InOut (= requestBody) to Camel
		log.info("Caller calling Camel with message: {}", body);
		String reply = template.requestBody("seda:start", body, String.class);
		log.info("Caller finished calling Camel and received reply: {}", reply);

		// give time for route to complete
		Thread.sleep(1000);
	}

}
